﻿using System.Collections.Generic;
using Sherwood.Content.UpdateServices.Attachments;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sherwood.Content.UpdateServices;
using Sherwood.Content;
using Sherwood.Content.UpdateServices.Tests;
using System.Linq;

namespace Sherwood.Content.UpdateServices.Attachments.Tests
{
    
    
    /// <summary>
    ///This is a test class for AttachmentSearchDocumentModifierTest and is intended
    ///to contain all AttachmentSearchDocumentModifierTest Unit Tests
    ///</summary>
    [TestClass()]
    public class AttachmentSearchDocumentModifierTest : MockedUpdateEnvironment
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Fill
        ///</summary>
        public void FillTestHelper<TAttachmentMeta>()
            where TAttachmentMeta : IAttachmentMeta
        {
            var target = new AttachmentSearchDocumentModifier<TAttachmentMeta>(); // TODO: Initialize to an appropriate value
            ISearchDocument searchDocument = new TestSearchDocument();

            var recordMetas = new List<IMeta>();
            var myAttachmentMeta = new MyAttachmentMeta();
            var attachment = myAttachmentMeta.CreateNewAttachment(null);
            attachment.FileName = "test.pdf";
            attachment.TextContent = "Her er innholdet";
            recordMetas.Add(myAttachmentMeta);
            Record.Setup(r => r.Metas).Returns(recordMetas.AsQueryable());
            
            target.Fill(searchDocument, Record.Object);

            Assert.AreEqual("test.pdf", searchDocument.Title);
            Assert.AreEqual("Her er innholdet", searchDocument.Description);
        }

        [TestMethod()]
        public void FillTest()
        {
            FillTestHelper<MyAttachmentMeta>();
        }
    }
}
